<?php

include 'DBconn.php';

class ClientSearch {

    public function getAllTrOut($customer_fk) 
	{
	   $ret = array();
       $query = "Select sh.serialnumber,sh.sales_con_code,concat(sh.no_of_days,' Days') as no_of_days,sh.customer_serialnumber_fk,sh.sc_remarks,sh.sales_con_date,
		sh.sales_con_status,sh.currency_serialnumber_fk,sh.sc_gst,sh.current_rate,ch.currency_name,IFNULL(cus.client_name,'Alliance Enterprices') as customer
		from sales_conformation_header as sh LEFT JOIN currency_header as ch ON ch.serialnumber = sh.currency_serialnumber_fk and ch.activestatus=1 LEFT JOIN 
		client_header as cus ON cus.serialnumber=sh.customer_serialnumber_fk and cus.activestatus=1 where sh.activestatus=1  and sh.sales_con_status!='DRAFT' 
		and sh.customer_serialnumber_fk='$customer_fk'";
        $s = mysql_query($query) or die(mysql_error());
        while ($row = mysql_fetch_object($s)) 
		{
            $temp = new VoSCHeaderSearch();
            $temp->sc_serialnumber = (int) $row->serialnumber;
            $temp->sales_con_code = $row->sales_con_code;
            $temp->customer_serialnumber_fk = (int) $row->customer_serialnumber_fk;
            $temp->sales_con_date = date("d-m-Y", strtotime($row->sales_con_date));
            $temp->sales_con_status =  $row->sales_con_status;
            $temp->currency_serialnumber_fk = (int) $row->currency_serialnumber_fk;
			$temp->no_of_days = $row->no_of_days;
            $temp->sc_remarks = $row->sc_remarks;
			$temp->customer = $row->customer;
			$temp->currency_name = $row->currency_name;
			$temp->current_rate = (double)$row->current_rate;
			$temp->sc_gst = (double)$row->sc_gst;
            $ret[] = $temp;
        }
        mysql_free_result($s);
        return $ret;
	}

    public function getAllTrIn($supplier_fk)
	{
       $ret = array();
        $query = "Select ph.po_serialnumber,ph.po_status,ph.po_remarks,ph.po_id,ch.client_name as supplier,ph.po_issue_date,ph.expected_datetime,ph.total_qty,IFNULL(ph.total_qty - IFNULL((Select IFNULL(Sum(gd.received_qty),0) from grn_detail as gd where gd.po_detserialnumber_fk IN(Select spd.po_detserialnumber from po_details as spd where spd.activestatus=1 and spd.po_serialnumber_fk=ph.po_serialnumber) 
		and gd.activestatus=1),0),0) as tot_balance_qty,curr.currency_name,ph.total_amount,ROUND((ph.total_amount*ph.current_rate),4) as sgd_amount,ROUND(((ph.total_amount*(ph.po_gst/100))*ph.current_rate),4) as gst_amount,ROUND(ph.current_rate*(ph.total_amount+(ph.total_amount*(ph.po_gst/100))),4) as sgd_total_amount from po_header as ph LEFT JOIN client_header as ch ON ch.activestatus=1 and 
		ch.serialnumber=ph.supplier_serialnumber_fk LEFT JOIN currency_header as curr ON curr.serialnumber=ph.currency_serialnumber_fk and curr.activestatus=1 where ph.activestatus=1 and ph.po_status!='DRAFT' and ph.supplier_serialnumber_fk='$supplier_fk'";
        $s = mysql_query($query) or die(mysql_error());
        while ($row = mysql_fetch_object($s)) 
		{
            $temp = new VoPoHeaderSearch();
            $temp->po_serialnumber = (int) $row->po_serialnumber;
            $temp->po_id = $row->po_id;
            $temp->po_issue_date = date("d-m-Y", strtotime($row->po_issue_date));
            $temp->expected_datetime = date("d-m-Y", strtotime($row->expected_datetime));
            $temp->total_qty = (int) $row->total_qty;
			$temp->tot_balance_qty = (int) $row->tot_balance_qty;
            $temp->po_status = $row->po_status;
			$temp->currency_name = $row->currency_name;
			$temp->supplier = $row->supplier;
			$temp->po_remarks = $row->po_remarks;
			$temp->total_amount = (double)$row->total_amount;
			$temp->gst_amount = (double)$row->gst_amount;
			$temp->sgd_amount = (double)$row->sgd_amount;
			$temp->sgd_total_amount = (double)$row->sgd_total_amount;
			$ret[] = $temp;
        }
      mysql_free_result($s);
      return $ret;
    }

}

class VoSCHeaderSearch 
{
    var $sc_serialnumber;
    var $sales_con_code;
    var $customer_serialnumber_fk;
	var $sales_con_date;
	var $sales_con_status;
	var $currency_serialnumber_fk;
	var $sc_remarks;
	var $sc_gst;
	var $no_of_days;
	var $current_rate;
	var $customer;
	var $currency_name;
}

class VoPoHeaderSearch 
{
	var $po_serialnumber; 
	var $po_id;
	var $po_issue_date;
	var $expected_datetime;
	var $total_qty;
	var $tot_balance_qty;
	var $po_status;
	var $currency_name;
	var $po_remarks;
	var $total_amount;
	var $gst_amount;
	var $sgd_amount;
	var $sgd_total_amount;
}

?>